home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 422_04 / mc_vs_sc.doc < prev    next >
Encoding:
Text File  |  1994-03-20  |  21.5 KB  |  504 lines

  1.     
  2.     
  3.     
  4.     
  5.     
  6.     
  7.     
  8.     
  9.     
  10.     
  11.     
  12.     
  13.                                        A
  14.                                    Comparison
  15.                                        of
  16.     
  17.     
  18.           ===========================================================
  19.           MM   MM  IIIIIII    CCCC   RRRRRR     OOO             CCCC
  20.           M M M M     I      C    C  R     R   O   O           C    C
  21.           M  M  M     I     C        R     R  O     O         C
  22.           M     M     I     C        RRRRRR   O     O  -----  C
  23.           M     M     I     C        R   R    O     O         C
  24.           M     M     I      C    C  R    R    O   O           C    C
  25.           M     M  IIIIIII    CCCC   R     R    OOO             CCCC
  26.           ===========================================================
  27.           
  28.                                      A N D
  29.           
  30.           ===========================================================
  31.            SSSSS   MM   MM     A     L        L                 CCCC
  32.           S     S  M M M M    A A    L        L                C    C
  33.           S        M  M  M   A   A   L        L               C
  34.            SSSSS   M     M  A     A  L        L        -----  C
  35.                 S  M     M  AAAAAAA  L        L               C
  36.           S     S  M     M  A     A  L        L                C    C
  37.            SSSSS   M     M  A     A  LLLLLLL  LLLLLLL           CCCC
  38.           ===========================================================
  39.     
  40.     
  41.     
  42.     
  43.     
  44.     
  45.     
  46.     
  47.     
  48.     
  49.     
  50.     
  51.     
  52.     
  53.     
  54.                        Copyright 1990-1994 Dave Dunfield
  55.                               All rights reserved
  56.     MICRO-C .vs. SMALL-C                                             Page: 1
  57.  
  58.  
  59.     1. INTRODUCTION
  60.     
  61.           The most common reaction of people hearing about DDS  MICRO-C  for
  62.        the first time is something like "Humph... Another version of the old
  63.        SMALL-C compiler". This couldn't be further from the truth.
  64.     
  65.                            MICRO-C IS NOT SMALL-C!!!
  66.     
  67.           MICRO-C is a completely  new  implementation  of  a  'C'  compiler
  68.        suitable for use on very small systems. It offers several  advantages
  69.        over SMALL-C:
  70.     
  71.         - It was designed from the  ground  up  to  be  easily  portable  to
  72.           different processors & computer  platforms.  Code  generators  are
  73.           available for 8080, 8051, 80x86, 8096,  6809,  68HC11  and  68HC16
  74.           cpu's, and an entire section of the manual is devoted  to  porting
  75.           the compiler.
  76.     
  77.           Although SMALL-C claims  to  be  easily  portable,  much  of  it's
  78.           arcitecture is oriented toward the original 8080 processor. For an
  79.           example of  how  this  affects  the  compiler,  compare  the  code
  80.           generated by the 8086 version of SMALL-C to reference stack (auto)
  81.           variables to that produced by MICRO-C.
  82.     
  83.         - It is a more complete implementation of the 'C' language, see  the
  84.           features comparison later in this document.
  85.     
  86.         - It produces faster, more compact code. See the  benchmark  results
  87.           later in this document.
  88.     
  89.         - MICRO-C employs  a  fully  tokenized  parser,  allowing  statement
  90.           analysis to be performed  on  16  bit  "tokens"  instead  of  text
  91.           strings as is  done  in  SMALL-C.  This  results  in  MUCH  faster
  92.           compilation.
  93.     
  94.         - Although it is higher in functionality than SMALL-C,  the  MICRO-C
  95.           compiler is much smaller than SMALL-C (Nearly half the size). This
  96.           allows it to run on very small computer systems.
  97.     
  98.     2. DETAILED COMPARISON OF COMPILERS
  99.     
  100.           The following pages contain a detailed comparison of  the  SMALL-C
  101.        version 2 compiler, and MICRO-C.
  102.     MICRO-C .vs. SMALL-C                                             Page: 2
  103.  
  104.  
  105.        2.1 'C' Implementation
  106.             = Data Types ===========+ SMALL-C V1 + SMALL-C V2 + MICRO-C +
  107.             int                     |    Yes     |    Yes     |   Yes   |
  108.             char                    |    Yes     |    Yes     |   Yes   |
  109.             unsigned int            |     No     |     No     |   Yes   |
  110.             unsigned char           |     No     |     No     |   Yes   |
  111.             pointers                |    Yes     |    Yes     |   Yes   |
  112.             pointers to pointers    |     No     |     No     |   Yes   |
  113.             structs & unions        |     No     |     No     |   Yes   |
  114.             Single dimension arrays |    Yes     |    Yes     |   Yes   |
  115.             Multi dimension arrays  |     No     |     No     |   Yes   |
  116.             Arrays of pointers      |     No     |     No     |   Yes   |
  117.             Arrays of structs       |     No     |     No     |   Yes   |
  118.             Typecast                |     No     |     No     |   Yes   |
  119.             sizeof                  |     No     |     No     |   Yes   |
  120.             Static globals & locals |     No     |     No     |   Yes   |
  121.             = Control Structures ===+ SMALL-C V1 + SMALL-C V2 + MICRO-C +
  122.             if/else                 |    Yes     |    Yes     |   Yes   |
  123.             while                   |    Yes     |    Yes     |   Yes   |
  124.             do/while                |     No     |    Yes     |   Yes   |
  125.             for                     |     No     |    Yes     |   Yes   |
  126.             switch/case             |     No     |    Yes     |   Yes   |
  127.             goto                    |     No     |    Yes     |   Yes   |
  128.             Conditional Expressions |     No     |    Yes     |   Yes   |
  129.             Inline assembler        |    Yes     |    Yes     |   Yes   |
  130.             = Pre-Processor ========+ SMALL-C V1 + SMALL-C V2 + MICRO-C +
  131.             #define (basic)         |    Yes     |    Yes     |   Yes   |
  132.             #define (Parameterized) |     No     |     No     |   Yes   |
  133.             #define (Multi-line)    |     No     |     No     |   Yes   |
  134.             #undef                  |     No     |     No     |   Yes   |
  135.             #include (single level) |    Yes     |    Yes     |   Yes   |
  136.             #include (nested)       |     No     |    Yes     |   Yes   |
  137.             #ifdef/#ifndef          |     No     |    Yes     |   Yes   |
  138.             = Misc features ========+ SMALL-C V1 + SMALL-C V2 + MICRO-C +
  139.             Optimization            |     No     |    Yes     |   Yes   |
  140.             Multiple memory models  |     No     |     No     |   Yes   |
  141.             Make/touch utility      |     No     |     No     |   Yes   |
  142.             Source linker           |     No     |     No     |   Yes   |
  143.             68HC08 code generator   |     No     |     No     |   Yes   |
  144.             6809 code generator     |     No     |     No     |   Yes   |
  145.             68HC11 code generator   |     No     |     No     |   Yes   |
  146.             68HC16 code generator   |     No     |     No     |   Yes   |
  147.             8080 code generator     |    Yes     |    Yes     |   Yes   |
  148.             8051 code generator     |     No     |     No     |   Yes   |
  149.             8086 code generator     |     No     |    Yes     |   Yes   |
  150.             8096 code generator     |     No     |     No     |   Yes   |
  151.             Complete standard lib   |     No     |    Yes     |   Yes   |
  152.             Interrupt serial I/O    |     No     |     No     |   Yes   |
  153.             Windowing library       |     No     |     No     |   Yes   |
  154.             TSR support             |     No     |     No     |   Yes   |
  155.     MICRO-C .vs. SMALL-C                                             Page: 3
  156.  
  157.  
  158.        2.2 Generated code quality
  159.     
  160.              To test the actual performace  of  code  generated  by  MICRO-C
  161.           against  code  generated  by  SMALL-C,  I  used  this  "Sieve   of
  162.           Eratosthenes" prime number generator program, taken from the  BYTE
  163.           benchmarks:
  164.     
  165.     
  166.     
  167.     
  168.     
  169.     /*
  170.      * The classic "Sieve of Eratosthenes" prime number program.
  171.      * from BYTE, January 1983.
  172.      */
  173.     #include <stdio.h>
  174.     #include "timer.c"          /* The timer subroutines */
  175.     
  176.     #define SIZE  8190
  177.     #define LOOP  100
  178.     #define TRUE  1
  179.     #define FALSE 0
  180.     
  181.     char flags [SIZE + 1];
  182.     
  183.     main()
  184.     {
  185.         int i, prime, k, count, iter;
  186.     
  187.         printf("BYTE Sieve Benchmark - %d iterations\n",LOOP);
  188.     
  189.     /* Start timer and execute loop */
  190.         startimer(timestamp);
  191.         for(iter = 1; iter <= LOOP; ++iter) {
  192.             count = 0;                          /* prime counter */
  193.             for(i = 0; i <= SIZE; ++i)          /* set all flags true */
  194.                 flags [i] = TRUE;
  195.             for(i = 0; i <= SIZE; ++i) {
  196.                 if(flags [i]) {                 /* found a prime */
  197.                     prime = i + i + 3;          /* twice index + 3 */
  198.     /*              printf ("\n%d", prime);     */
  199.                 for(k = i + prime; k <= SIZE; k+= prime)
  200.                     flags [k] = FALSE;          /* kill all multiple */
  201.                 ++count; } } }                  /* primes found */
  202.         elapsed(timestamp);                     /* Calculate time taken */
  203.     
  204.     /* Report results */
  205.         printf("%d primes.\n\n", count);        /* primes found on 100th pass */
  206.         printf("Elapsed time: %02d:%02d:%02d.%02d\n",
  207.             timestamp[1], timestamp[0], timestamp[3], timestamp[2]);
  208.     }
  209.     MICRO-C .vs. SMALL-C                                             Page: 4
  210.  
  211.  
  212.        2.3 Speed of compilation
  213.     
  214.              To show the relative compilation times,  I  wrote  this  simple
  215.           MICRO-C program, using the timing routines shown below, to execute
  216.           the compilers & report the time taken:
  217.     
  218.     
  219.     
  220.     
  221.     
  222.     #include <stdio.h>
  223.     #include "timer.c"          /* The timer subroutines */
  224.     
  225.     main()
  226.     {
  227.         startimer(timestamp);
  228.         system("CC SIEVE");             /* Execute the SMALL-C compiler */
  229.         elapsed(timestamp);
  230.         printf("Elapsed time: %02d:%02d:%02d.%02d\n\n",
  231.             timestamp[1], timestamp[0], timestamp[3], timestamp[2]);
  232.     
  233.         startimer(timestamp);
  234.         system("MCC SIEVE.C SIEVE.ASM");/* Execute the MICRO-C compiler */
  235.         elapsed(timestamp);
  236.         printf("Elapsed time: %02d:%02d:%02d.%02d\n",
  237.             timestamp[1], timestamp[0], timestamp[3], timestamp[2]);
  238.     }
  239.     
  240.              NOTE: The results from the above program will include the  time
  241.           taken to load the compilers. To minimize this, all tests were  run
  242.           from a RAMdisk. This eliminates disk seek time, and  reduces  load
  243.           time to the speed of a memory to memory copy.
  244.     MICRO-C .vs. SMALL-C                                             Page: 5
  245.  
  246.  
  247.        2.4 Timing the tests
  248.     
  249.              These subroutines were used to time  the  programs,  using  the
  250.           MS-DOS internal clock which has a resolution of 1/100 of a second:
  251.     
  252.     
  253.     
  254.     
  255.     
  256.     char timestamp[4];          /* Stores initial timestamp */
  257.     
  258.     /*
  259.      * Record system time for later calculation
  260.      */
  261.     startimer() asm
  262.     {
  263.             MOV     AH,2CH      ; Get time function
  264.             INT     21H         ; Ask DOS
  265.             MOV     SI,4[BP]    ; Get pointer to timestamp
  266.             MOV     [SI],CX     ; Record hours & minites
  267.             MOV     2[SI],DX    ; Record seconds & hundreds
  268.     }
  269.     
  270.     /*
  271.      * Calculate elapsed time since timestamp recorded
  272.      */
  273.     elapsed() asm
  274.     {
  275.             MOV     AH,2CH      ; Get time function
  276.             INT     21H         ; Ask DOS
  277.             MOV     SI,4[BP]    ; Pointer to timestamp
  278.             SUB     DL,2[SI]    ; Convert 100ths
  279.             JNC     ELAP1       ; No borrow
  280.             ADD     DL,100      ; Re-adjust
  281.             DEC     DH          ; Reduce seconds
  282.     ELAP1:  MOV     2[SI],DL    ; Save elapsed hundreds
  283.             SUB     DH,3[SI]    ; Convert seconds
  284.             JNS     ELAP2       ; No borrow
  285.             ADD     DH,60       ; Re-adjust
  286.             DEC     CL          ; Reduce minites
  287.     ELAP2:  MOV     3[SI],DH    ; Save elapsed seconds
  288.             SUB     CL,[SI]     ; Convert minites
  289.             JNS     ELAP3       ; No borrow
  290.             ADD     CL,60       ; Re-adjust
  291.             DEC     CH          ; Adjust hours
  292.     ELAP3:  MOV     [SI],CL     ; Save elapsed minites
  293.             SUB     CH,1[SI]    ; Convert hours
  294.             MOV     1[SI],CH    ; Save elapsed hours
  295.     }
  296.     MICRO-C .vs. SMALL-C                                             Page: 6
  297.  
  298.  
  299.        2.5 Test results
  300.     
  301.              After compiling the programs, I ran  the  various  tests  on  a
  302.           standard 8-Mhz IBM PC/AT, with these results:
  303.     
  304.     E:\>dir
  305.     
  306.      Volume in drive E is VDISK  V3.3
  307.      Directory of  E:\
  308.     
  309.     CC       EXE    40626   4-27-93  /* SMALL-C compiler */
  310.     MCC      COM    24154   4-27-93  /* MICRO-C compiler */
  311.     TIMER    C       1094   4-27-93  /* The timer subroutines */
  312.     TIMECOMP C        527   4-27-93  /* The compiler timer */
  313.     SIEVE    C       1149   4-27-93  /* The test program */
  314.     SIEVE-S  EXE    16946   4-27-93  /* SMALL-C produced this */
  315.     SIEVE-M  COM     1744   4-27-93  /* MICRO-C produced this */
  316.     TIMECOMP COM     1908   4-27-93  /* Executable compiler timer */
  317.             8 File(s)    430080 bytes free
  318.     
  319.     E:\>sieve-s     /* The SMALL-C version: 1 min, 28.98 secs */
  320.     BYTE Sieve Benchmark - 100 iterations
  321.     1899 primes.
  322.     
  323.     Elapsed time: 00:01:28.98
  324.     
  325.     E:\>sieve-m     /* The MICRO-C version: 0 min, 40.43 secs */
  326.     BYTE Sieve Benchmark - 100 iterations
  327.     1899 primes.
  328.     
  329.     Elapsed time: 00:00:40.43
  330.     
  331.     E:\>
  332.     
  333.     **NOTE: Before running TIMECOMP, I created a "generic" STDIO.H
  334.             file which was suitable for both compilers.
  335.     
  336.     E:\>timecomp    /* Times to compile the program */
  337.     Small-C Compiler, Version 2.1, (Rev. 75)
  338.     Copyright 1982, 1983, 1985 J. E. Hendrix
  339.     Elapsed time: 00:00:04.72       /* SMALL-C 4.72 secs */
  340.     
  341.     MICRO-C Compiler
  342.     Copyright 1988-1993 Dave Dunfield
  343.     All rights reserved.
  344.     Elapsed time: 00:00:01.15       /* MICRO-C 1.15 secs */
  345.     
  346.     E:\>
  347.     MICRO-C .vs. SMALL-C                                             Page: 7
  348.  
  349.  
  350.     3. OTHER ADVANTAGES OF MICRO-C
  351.     
  352.           In addition to being a superiour and more portable  compiler,  The
  353.        MICRO-C package also offers these advantages:
  354.     
  355.        3.1 Utilities
  356.     
  357.              MICRO-C Comes with the following utilities (all  with  complete
  358.           MICRO-C source code):
  359.     
  360.         CC      - Command Coordinator, combines pre-processor, compiler,
  361.                   optimizer, assembler and linker into a single command.
  362.                   Command line parameters allow very flexible operation.
  363.     
  364.         MAKE    - Automates building of larger (multi module) programs.
  365.     
  366.         TOUCH   - Set timestamp of file to current or specified date.
  367.                   (Used with MAKEs dependancy checking)
  368.     
  369.         SLINK   - Source LINKer, Allows pre-compiled (assembler) source to
  370.                   be kept in a library and included as needed to resolve
  371.                   external references. Useful when MICRO-C is used as cross
  372.                   compiler for systems not supporting an object linker.
  373.     
  374.         SLIB    - Utility for updating and maintaining a source library.
  375.     
  376.         SINDEX  - Automatically indexes a source library for use by SLINK.
  377.     
  378.         SCONVERT- Converts assembly language source for use by SLINK.
  379.     
  380.         EXE2BIN - Converts MS-DOS EXE files to a binary image, useful for
  381.                   users of later versions of DOS which no longer include
  382.                   this utility.
  383.     
  384.         MCP     - The MICRO-C Pre-processor
  385.     
  386.         MCC     - The MICRO-C Compiler
  387.     
  388.         MCO     - The MICRO-C Optimizer
  389.     MICRO-C .vs. SMALL-C                                             Page: 8
  390.  
  391.  
  392.        3.2 Example Programs
  393.     
  394.              MICRO-C comes with the following archives of  example  programs
  395.           (all with complete MICRO-C source code):
  396.     
  397.     CUTIL: 'C' utilities & related programs
  398.         CCREF       - 'C' source cross referencing program
  399.         COMEXT      - Extract comments from 'C' sources
  400.         CVTCOM      - Convert C++ '//' comments to '/* */'
  401.         OBSCURE     - Make 'C' program un-readable (but it still compiles)
  402.         PPC         - Pretty Printer for 'C' (source formatter)
  403.         SHELL       - Command line / interactive shell program
  404.     
  405.     DOSUTIL: DOS utilities
  406.         ANYFILE     - Set ERRORLEVEL on file matching patterns
  407.         BOOTMENU    - "boot" menu, allowing different AUTOEXEC and CONFIG files
  408.         CALC        - A TSR programmers (HEX/DECIMAL) calculator
  409.         CAN         - Automatically append arguments to ".COM" files
  410.         CHAINSAW    - Remove an entire directory tree
  411.         CHATTR      - Change attributes of DOS files
  412.         CMOS        - Read/Write/Verify CMOS RAM from/to/with disk file
  413.         COMCHK      - Checksum .COM file every time it runs
  414.         CSET        - TSR map of IBM PC character set
  415.         DIFF        - Displays differences between text files
  416.         DUMP        - Hex/Octal/ASCII file dump utility
  417.         EQUIP       - Display hardware installed in PC
  418.         GREP        - Like unix "GREP" search utility
  419.         HEM         - Hardware Exception Monitor TSR to trap unexpected ints
  420.         HEXED       - Screen oriented Hex file editor
  421.         LZC         - Laser commander TSR to control HP compatible printers
  422.         MEMSAVE     - Saves memory image to file
  423.         MTERM       - Tiny (10k!) TSR ANSI terminal with XMODEM
  424.         OFF         - Screen saver
  425.         PARK        - Configurable hard disk parking utility
  426.         PCD         - PC "countdown" timer
  427.         RETAB       - Retabulates files to different TAB stops
  428.         SCRUB       - Utility for cleaning floppy drives
  429.         SHOWEXE     - Displays information about a .EXE file
  430.         SIZE        - Show file(s) exact size and number of lines
  431.         STUFF       - Stuffs keycodes into the keyboard buffer
  432.         TFB         - TSR File Browser
  433.         TIMEIT      - Time execution of other DOS commands
  434.         TR          - Like unix TR (translate) command
  435.         TYPE4       - Display files with tabs at 4 character intervals
  436.         VALIDATE    - PD ver of McAfee's validate. Verify files with two CRC's
  437.     
  438.     LAPTALK: A small (20K) but powerful comms pogram
  439.         LAPTALK     - A terminal program with script interpreter
  440.         XMODEM      - External file transfer program
  441.     
  442.     MICROCAD: A VGA drawing program
  443.         MICROCAD    - Mouse based drawing program
  444.         MCPRINT     - Prints MICROCAD files on Laserjet or Epson printers
  445.         MCDRAW      - Minimal routines to display MICROCAD file in other pgms
  446.         FE          - Font Editor
  447.     MICRO-C .vs. SMALL-C                                             Page: 9
  448.  
  449.  
  450.     MISC: Other misc. programs
  451.         ASM86       - 8086 assembler
  452.         BASIC       - A simple BASIC interpreter
  453.         BIGNUM      - Add/Sub/Mul/Div/Mod very large numbers
  454.         BITARRAY    - Example of using an array of bits.
  455.         BJ          - Blackjack (21) game
  456.         BYTESWAP    - Example of using UNION's
  457.         CASTLE      - A large text based "adventure" game
  458.         FIBO        - Calculates a fibonacci series
  459.         FORTUNE     - A "fortune cookie" - Displays random quotation
  460.         HANOI       - Solves "towers of hanoi" on screen
  461.         HELLO       - Standard 'C' demo program
  462.         HFTEXT      - Text compressor using Huffman encoding
  463.         KIDSMENU    - Colorful mouse/keyboard based menuing system for kids
  464.         KMEDIT      - Editor for kids menu database
  465.         LONGCALC    - A "long" (32 BIT) desk calculator
  466.         MDCFS       - Minimal DOS compatible File System
  467.         OBFUSC      - Example of how NOT to write 'C'
  468.         PRIME       - Calculates prime numbers
  469.         PRIME1      - Another prime number calculator
  470.         PTR2FUNC    - Demo's use of pointers to functions
  471.         RAIN        - Makes characters "fall" off the screen
  472.         RDC         - Another text compression program
  473.         RLTEXT      - Text compression using run length encoding
  474.         ROBOFACE    - Draws a "robot face"
  475.         SELFDUP     - A self-replicating 'C' program!
  476.         TEXTNUM     - Converts numbers to text equivalent
  477.         TTT3D       - 3 dimensional tic-tac-toe
  478.         WINDEMO     - Demonstrates MICRO-C windowing
  479.  
  480.  
  481.  
  482.                               MICRO-C .vs. SMALL-C
  483.  
  484.                                TABLE OF CONTENTS
  485.  
  486.  
  487.                                                                          Page
  488.  
  489.      1. INTRODUCTION                                                        1
  490.  
  491.  
  492.      2. DETAILED COMPARISON OF COMPILERS                                    1
  493.  
  494.         2.1 'C' Implementation                                              2
  495.         2.2 Generated code quality                                          3
  496.         2.3 Speed of compilation                                            4
  497.         2.4 Timing the tests                                                5
  498.         2.5 Test results                                                    6
  499.  
  500.      3. OTHER ADVANTAGES OF MICRO-C                                         7
  501.  
  502.         3.1 Utilities                                                       7
  503.         3.2 Example Programs                                                8
  504.